<template>
<div class="test" style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
            <a-col :md="6" :sm="12">
            <a-form-item label="培养模式">
              <a-select allowClear v-model="queryParam.pymsm" @change="pymsChange">
                <a-select-option v-for="i in TYPE0347" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12" v-if="queryParam.pymsm === '01'">
            <a-form-item label="门类">
              <a-select allowClear v-model="queryParam.xkmlm" showSearch :filterOption="filterOption" @change="mlChange">
                <a-select-option v-for="i in selectMenu.subjectList" :key="i.id" :value="i.xkdm">{{i.xkdm}}-{{ i.xkmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12" v-if="queryParam.pymsm === '01'">
            <a-form-item label="学科">
              <a-select allowClear v-model="queryParam.xkm" showSearch :filterOption="filterOption" @change="xkChange">
                <a-select-option v-for="i in selectMenu.xk" :key="i.id" :value="i.xkdm">{{i.xkdm}}-{{ i.xkmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12" v-if="queryParam.pymsm === '02'">
            <a-form-item label="领域">
              <a-select allowClear v-model="queryParam.xkm" showSearch :filterOption="filterOption" @change="lyChange">
                <a-select-option v-for="i in selectMenu.subjectList" :key="i.id" :value="i.xkdm">{{i.xkdm}}-{{ i.xkmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12" v-if="queryParam.pymsm === '02' || queryParam.pymsm === '01'">
            <a-form-item label="专业">
              <a-select allowClear v-model="queryParam.xkzym" >
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.xkdm">{{ i.xkdm+'-'+i.xkmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="年级">
              <a-select allowClear v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :sm="{span:20}" :xl="{span:10}">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatchDel">批量删除</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col> -->
          <a-col :md="8" :sm="12">
            <span class="table-page-search-submitButtons" >
           <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
            <a-button type="primary" @click="handleBatchDel">批量删除</a-button>
<!--            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :scroll="{ x: 1500 }"
      :pagination="pagination"
			@change="handleTableChange"
    >
    <template slot="action" slot-scope="text,record">

        <a @click="handleEdit(record.id,record.fsxlxm)">修改</a>
        <a @click="handleDel(record.id)">删除</a>



      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
     <fractional-edit @close="handleEditClose" @success="handleEditSuccess" :info="departmentsEditData" :departmentsEditVisiable="departmentsEditVisiable"></fractional-edit>
     <fractional-adit @close="handleEditClose" @success="handleEditSuccess" :info="departmentsEditData" :departmentsEditVisiable="departmentsAditVisiable"></fractional-adit>
</div>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'
import FractionalEdit from './fractionalEdit'
const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072','TYPE0503','TYPE0075','TYPE0347']
import FractionalAdit from './fractionalAdit'
export default {
  components: {
    STable,
    FractionalEdit,
    FractionalAdit
  },
  data () {
    return {
      advanced: true,
      AuditHandleVisible: false,
      loading: false,
      departmentsEditVisiable:false,
      departmentsAditVisiable:false,
      data: [],
      idObj:[],
      selectedRowKeys:[],
      // 查询参数
      queryParam: {
        'xkmlm':'',
        "xkm":'',
        'xkzym':'',
        'zsnj':'',
        "pymsm":'01'
      },
      departmentsEditData: {
        hzfs: '',
        zjh: '',
        fzyxwjh: '',
        zyxwjh: ''
      },
      postParams: {

      },
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学科代码',
          dataIndex: 'xkzym'
        },
        {
          title: '招生年度',
          dataIndex: 'zsnj'
        },
        {
          title: '学科专业名称',
          dataIndex: 'xkzymc'
        },
        {
          title: '外语听力',
          dataIndex: 'wytlfsx'
        },
        {
          title: '外语笔试',
          dataIndex: 'wybsfsx'
        },
        {
          title: '外语口语',
          dataIndex: 'wykyfsx'
        },
        {
          title: '外语总分',
          dataIndex: 'wyzffsx'
        },
        {
          title: '业务课一',
          dataIndex: 'ywkyfsx'
        },
        {
          title: '业务课二',
          dataIndex: 'ywkefsx'
        },
        {
          title: '业务课三',
          dataIndex: 'ywksfsx'
        },
        {
          title: '总成绩',
          dataIndex: 'ywkzcjfsx'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      // custom table alert & rowSelection
      options: {
        alert: { show: false }
      },
      selectMenu: {
        yx: [], // 院系,
        xk:[],
        zy:[]
      },
      recruitEditData: {},
      pagination: {
					current: 1
        },
      selectedRowKeys: [],
      selectedRows:''
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'], // 年级
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0347: state => state.app['TYPE0347']  
    })
  },
  created () {
    let code ="01"
    this.initSelectMenu(code)
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu (xklb) {
       this.$api.base.getSchoolYear().then(res=>{
        this.queryParam.zsnj=res.data.doctoralAdmissionYear;
        this.loadData({
        pageNum:1,
        pageSize:10
      })
      })
      this.$api.base.subjectAll({xklb}).then(res => {
        this.$set(this.selectMenu , 'subjectList', res.data)
      })
      console.log(this.selectMenu.subjectList)
    },
     pymsChange(code){
      this.$set(this.queryParam, 'xkm', '')
      this.$set(this.queryParam, 'xkmlm', '')
      this.$set(this.queryParam, 'xkzym', '')
      this.$set(this.selectMenu,'zy','')
      this.initSelectMenu(code == '01' ? '01' : '04')
    },
    subjectChange (code) {
      this.$set(this.queryParam, 'xkdm', '')
      if (code) {
        this.$api.base.subjectAll({fjxkdm: code, xklb: '02'}).then(res => {
          this.$set(this.selectMenu, 'subSubjectList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'subSubjectList', [])
      }
    },
      filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    // 选择院系
    yxChange (code) {
      	console.log(code)
        this.postParams.xkdm = code
        this.queryParam.xkm='';
        this.queryParam.xkzym='';
        this.$set(this.selectMenu,'zy','')
        this.$set(this.selectMenu,'xk','')
        if(code){
        var yx = this.selectMenu.yx
				this.$api.base.subjectAll({
					fjxkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							yx: yx,
              xk: res.data,
              zy:[]
						}
					}
        })
        }
    },
    xkChange(code){
          this.postParams.xkdm = code
        var yx = this.selectMenu.yx
        var xk = this.selectMenu.xk
        this.$set(this.selectMenu,'zy','')
        if(code){
         this.queryParam.xkzym='';
				this.$api.base.getDisline({
					xkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							yx: yx,
              xk: xk,
              zy:res.data
						}
					}
        })
        }
    },
      mlChange (code) {
        console.log(code)
        // this.queryParam.xk='';
        // this.queryParam.zy='';
        this.queryParam.xkm=''
        this.queryParam.xkzym=''
        this.$set(this.selectMenu,'xk','')
        this.$set(this.selectMenu,'zy','')
        if(code){
          this.xkdm=code;
        var ml = this.selectMenu.ml
				this.$api.base.subjectAll({
					fjxkdm: code
				}).then(res => {
					if (res.data) {
            this.$set(this.selectMenu,'xk',res.data)
					}
        })
        }
    },
    lyChange(code){
         this.queryParam.xkzym=''
         this.$set(this.selectMenu,'zy','')
         if(code){
           this.xkdm=code;
        var ml = this.selectMenu.ml;
        var subjectList = this.selectMenu.subjectList;
				this.$api.base.linkageMajor({
					xkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							ml: ml,
              subjectList: subjectList,
              zy:res.data
						}
					}
        })
         }
    },
    onSelectChange (selectedRowKeys,selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows=selectedRows;
    },
    // 加载数据
  loadData(parameter = {}) {
    if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
      let params = Object.assign(this.queryParam, parameter)
      this.loading = true;
      this.$api.doctorRecruit.fractionalList(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
        this.pagination = pagination;
        if (res.data && res.data.rows.length) {
          this.data = res.data.rows;
        }
        this.loading = false;
      })
    },
    // 分页
			handleTableChange(pagination, filters, sorter) {
				console.log(pagination);
				const pager = { ...this.pagination
				};
				pager.current = pagination.current;
				this.pagination = pager;
				this.loadData({
					pageSize: 10,
					pageNum: pagination.current
				});
			},
    // 选择招生年度
    zsndChange () {

    },
    // 修改
    handleEdit (key,fsxlxm) {
      this.$api.doctorRecruit.fractionalId(key).then(res=>{
        // console.log(res)
        if(fsxlxm=='01'){
         this.departmentsEditVisiable = true
        }else{
          this.departmentsAditVisiable =true
        }
				if(res.data){
					this.departmentsEditData = res.data
				}
			})
    },
    // 删除
    handleDel (key) {
      let _this=this;
      this.$confirm({
         title: '确定删除?',
         onOk() {
           console.log('OK');
            _this.$api.doctorRecruit.fractionalDelete(key).then(res=>{
            if (res.status==1) {
              _this.loadData({
              pageSize: 10,
              pageNum: _this.pagination.current
            });
            _this.$message.success(res.msg)
            }else{
              _this.$message.warning(res.msg)
            }
           })
         },
         onCancel() {
           console.log('Cancel');
         },
         class: 'test',
       });

    },
     // 添加成功
    handleEditSuccess () {
      this.departmentsEditVisiable = false
       this.departmentsAditVisiable = false
			this.loadData({
        pageSize: 10,
        pageNum: this.pagination.current
      })
      // this.$message.success('添加成功')
    },
    // 导出
    handleExport () {
      console.log('导出')
      this.$export('admissions/bscsfsxxx/export',this.queryParam)
    },
     // 关闭添加弹层
    handleEditClose () {
      this.departmentsEditVisiable = false
      this.departmentsAditVisiable = false
    },
    // 批量删除
    handleBatchDel () {
      let _this=this;
       if (!this.selectedRowKeys.length) {
        this.$message.warning('请选择需要报到的学生')
        return
      }
      this.$confirm({
         title: '确定删除?',
         onOk() {
           console.log('OK');
            let para=[],params
      _this.selectedRows.forEach(item=>{
        para.push(item.id);
      })
      params=para.join(',')
      _this.$api.doctorRecruit.fractionalDelete(params).then(res=>{
        console.log(res.status)
        if (res.status==1) {
           _this.selectedRowKeys = [];
          _this.loadData({
					pageSize: 10,
					pageNum: _this.pagination.current
        });
        _this.$message.success(res.msg)

        }else{
          _this.$message.warning(res.msg)
        }
      })
         },
         onCancel() {
           console.log('Cancel');
         },
         class: 'test',
       });


    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
  .test /deep/ .ant-drawer-mask .ant-drawer-content-wrapper{
    width: 100% !important
  }
</style>
